package com.gomoku.backend.controller.pk;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.gomoku.backend.service.pk.ReceiveBotMoveSerice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
public class ReceiveBotMoveController {
    @Autowired
    private ReceiveBotMoveSerice botMoveSerice;

    @PostMapping("/pk/receivebotmove/")
    public String startGame(@RequestParam MultiValueMap<String,String> data){
        // user_id bot_id direction 有三个参数
        Integer userId = Integer.valueOf(Objects.requireNonNull(data.getFirst("userId")));
        Integer botId = Integer.valueOf(Objects.requireNonNull(data.getFirst("botId")));
        String direction = data.getFirst("direction");
        JSONObject jsonObject = JSON.parseObject(direction);
        Integer row = jsonObject.getInteger("r");
        Integer col = jsonObject.getInteger("c");
        return botMoveSerice.botmove(userId,botId,row,col);
    }

}
